let v = new Vue({
    el: '#app',
    data: function () {
        return {
            currentUserName: '',
            currentUserAvatar: '',
            /*=============================首页分布图开始==========================*/
            DeptNumDoctor: [], //储存每个科室有多少医生
            tableIndexNoticeData: [],
            /*=============================首页分布图开始==========================*/

            /*==========================用户信息模块return开始=============================*/
            searchUsername: '',//查询输入框的账号
            searchStatus: '',//查询输入框的状态
            searchNick: '',  //查询输入框的昵称
            tableUserData: [],
            totalUser: 0,//总条数
            pageSizeUser: 5,//每页5条
            currentPageUser: 1,//
            showRechargeDialog: false, // 控制充值模态框的显示与隐藏
            rechargeUserId: null, // 存储充值用户的 ID
            rechargeAmount: null, // 存储充值金额
            editedUser: {},//编辑用户对象
            editModalUserVisible: false, // 编辑模态框的显示状态
            editUserForm:{
                username:[
                    {required: true, message: '请输入用户名', trigger: 'blur'},
                    {pattern: /^[a-zA-Z\u4e00-\u9fa5]{2,10}$/, message: '用户名必须是2~10长度的字符组成，且不允许使用标点符号', trigger: 'blur'}
                ],
                gender:[
                    {required: true, message: '性别不能为空', trigger: 'blur'}
                ],
                phone:[
                    {pattern:/^1[3456789]\d{9}$/, message: '请输入正确的手机号码'}
                ],
                email:[
                    {required: true, message: '请输入邮箱', trigger: 'blur'},
                    {pattern: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/, message: '邮箱格式错误', trigger: 'blur'}
                ],
                birthday:[
                    {required: true, message: '出生日期不能为空', trigger: 'blur'},
                ],
            },
            /*========================用户信息模块return结束===================================*/

            /*==========================医生模块return开始================================*/
            searchNo: '',//查询输入框的工号
            searchName: '',//查询输入框的username
            isCollapse: false,
            defaultOpeneds: ["1"], // 默认展开的菜单项
            selectedIndex: "1", //选中的菜单项的index值
            multipleSelection: [],//index=2,储存选择的条数
            tableDoctorData: [],
            tableDoctorMhData: [],
            searchData: [],//储存查询结果的数组
            total: 0,//总条数
            pageSize: 5,//每页5条
            currentPage: 1,//
            ids: [],
            departments: [], // 存储科室数据
            dialogDoctorVisible: false, // 控制增加模态框的可见性
            newDoctor: { // 包含新医生的数据
                no: '',
                username: '',
                nickName: '',
                password: '',
                gender: '',
                deptname: '',
                birthday: '',
                phone: '',
                email: '',
                degree: '',
                joinTime: '',
                deptId: ''
            },
            editedDoctor: {}, // 正在编辑的医生对象
            editModalVisible: false, // 编辑模态框的显示状态
            // 表单规则
            addDoctorRules: {
                no: [
                    {required: true, message: '请输入医生工号', trigger: 'blur'},
                    {pattern: /^D\d{4}$/, message: '工号必须D开头并且是5个长度的字符组成', trigger: 'blur'}
                ],
                username:[
                    {required: true, message: '请输入帐号', trigger: 'blur'},
                ],
                nickName:[
                    {required: true, message: '请输入用户名', trigger: 'blur'},
                    {pattern: /^[a-zA-Z\u4e00-\u9fa5]{2,10}$/, message: '用户名必须是2~10长度的字符组成，且不允许使用标点符号', trigger: 'blur'}
                ],
                password:[
                    {required: true, message: '请输入密码名', trigger: 'blur'},
                ],
                gender:[
                    {required: true, message: '性别不能为空', trigger: 'blur'}
                ],
                phone:[
                    {required: true, message: '手机号不能为空', trigger: 'blur'},
                    {pattern:/^1[3456789]\d{9}$/, message: '请输入正确的手机号码'}
                ],
                email:[
                    {required: true, message: '请输入邮箱', trigger: 'blur'},
                    {pattern: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/, message: '邮箱格式错误', trigger: 'blur'}
                ],
                deptId:[
                    {required: true, message: '科室不能为空', trigger: 'blur'},
                ],
                birthday:[
                    {required: true, message: '出生日期不能为空', trigger: 'blur'},
                ],
                joinTime:[
                    {required: true, message: '入职时间不能为空', trigger: 'blur'},
                ]
            },
            editDoctorRules:{
                no: [
                    {required: true, message: '请输入医生工号', trigger: 'blur'},
                    {pattern: /^D\d{4}$/, message: '工号必须D开头并且是5个长度的字符组成', trigger: 'blur'}
                ],
                username:[
                    {required: true, message: '请输入帐号', trigger: 'blur'},
                ],
                nickName:[
                    {required: true, message: '请输入用户名', trigger: 'blur'},
                    {pattern: /^[a-zA-Z\u4e00-\u9fa5]{2,10}$/, message: '用户名必须是2~10长度的字符组成，且不允许使用标点符号', trigger: 'blur'}
                ],
                gender:[
                    {required: true, message: '性别不能为空', trigger: 'blur'}
                ],
                phone:[
                    {required: true, message: '手机号不能为空', trigger: 'blur'},
                    {pattern:/^1[3456789]\d{9}$/, message: '请输入正确的手机号码'}
                ],
                email:[
                    {required: true, message: '请输入邮箱', trigger: 'blur'},
                    {pattern: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/, message: '邮箱格式错误', trigger: 'blur'}
                ],
                deptId:[
                    {required: true, message: '科室不能为空', trigger: 'blur'},
                ],
                birthday:[
                    {required: true, message: '出生日期不能为空', trigger: 'blur'},
                ],
                joinTime:[
                    {required: true, message: '入职时间不能为空', trigger: 'blur'},
                ]
            },
            rules: {},
            /*==========================医生模块return结束=============================*/

            /*=========================科室信息模块return开始========================================*/
            tableDeptData: [],
            searchDeptName: '',//绑定查询输入框里面的值
            totalDept: 0,//总条数
            pageSizeDept: 5,//每页5条
            currentPageDept: 1,//
            totalDeptAndDoctor: 0,//总条数
            pageSizeDeptAndDoctor: 5,//每页5条
            currentPageDeptAndDoctor: 1,//
            totalDeptAndDoctorAppoint: 0,//总条数
            pageSizeDeptAndDoctorAppoint: 5,//每页5条
            currentPageDeptAndDoctorAppoint: 1,//
            editModalDeptVisible: false,
            editModalAppointVisible: false,
            newDept:{
                deptremark: ''
            },
            newAppoint:{
                schedulTime: '',
                sourceTotal: '',
                sourceSurplus: '',
                doctorNo: '',
            },
            editedDept: {},
            editedAppoint:{},
            editDeptRules:{
                deptremark:[
                    {required: true, message: '请输入科室备注', trigger: 'blur'},
                    {pattern: /^.{1,20}$/, message: "科室备注必须是1~20长度的字符组成'", trigger: 'blur'}
                ]
            },
            editAppointRules: {
                schedulTime: [
                    {required: true, message: '请输入排班日期', trigger: 'blur'},
                ],
                sourceTotal: [
                    {required: true, message: '请输入号源总量', trigger: 'blur'},
                ],
                sourceSurplus: [
                    {required: true, message: '请输入剩余号源', trigger: 'blur'},
                ]
            },
            showDoctorCard:false,
            showDeptCard:false,
            ListDoctor:[],
            currentDoctorId: -1, // 初始值为一个不存在的科室ID
            tableAppointData:[],//每天排班列表
            showAppointCard:false,
            currentDoctorName: '', // 当前医生的姓名
            currentDoctorNo: '',//当前医生的工号
            loading: false,
            showEmpty:true,
            no: '',
            nickName: '',
            deptId: '',
            searchDeptAppointDate: '',
            doctor:{
                currentDoctorName: '', // 当前医生的姓名
            },
            appointIds:[],
            newAppointRules:{
                schedulTime: [
                    {required: true, message: '请输入排班日期', trigger: 'blur'},
                ],
                sourceTotal: [
                    {required: true, message: '请输入号源总量', trigger: 'blur'},
                ],
                sourceSurplus: [
                    {required: true, message: '请输入剩余号源', trigger: 'blur'},
                ]
            },
            dialogAppointVisible: false,
            showSourceCard: false,
            showSource: false,
            AppointId: '',
            currentAppointId: -1, // 初始值为一个不存在的排班ID
            loadingSource: false,
            ListSource:[],
            newSource:{
                endTime: '',
                sourceSurplus: '',
                sourceTotal: '',
                schedulTime: '',
                appointId: ''
            },
            dialogSourceVisible: false,
            newSourceRules:{
                sourceTotal: [
                    {required: true, message: '请输入号源总量', trigger: 'blur'},
                ],
                sourceSurplus: [
                    {required: true, message: '请输入剩余号源', trigger: 'blur'},
                ]
            },
            AppointTotal: '',//当天排班的号源总量
            AppointSurplus: '',
            sourceTotal: 0,//从数据库累加的号源总量
            sourceSurplus: '',
            AppointStatus: '',
            /*=========================科室信息模块return结束========================================*/

            /*==========================药品管理模块return开始===========================================*/
            tableDrugData:[],
            drugNo: '',
            drugName: '',
            totalDrug: 0,//总条数
            pageSizeDrug: 5,//每页5条
            currentPageDrug: 1,//
            editedDrug: {},
            showDrug: {},
            editModalDrugVisible: false,
            showModalDrugVisible: false,
            newDrug:{
                id: '',
                drugNo: '',//药品编号
                drugName: '',//药品名称
                inventory: '',//库存
                unitprice: '',//单价
                unit: '',//单位
                usage: '',//用法1，2，3
                remark: '',//功能主治
                dosage:'',//用量
                attention:''//注意事项
            },
            drugRules: {
                drugNo: [
                    {required: true, message: '药品编号不能为空', trigger: 'blur'},
                    {pattern: /^[A-Z]\d+$/, message: '药品编号必须是大写字母开头，后面跟数字', trigger: 'blur'}
                ],
                drugName: [
                    {required: true, message: '药品名称不能为空', trigger: 'blur'},
                ],
                inventory: [
                    {required: true, message: '库存不能为空', trigger: 'blur'},
                    {pattern: /^[1-9]\d*$/, message: '库存必须是正整数', trigger: 'blur'}
                ],
                unitprice: [
                    {required: true, message: '单价不能为空', trigger: 'blur'}
                ],
                unit: [
                    {required: true, message: '单位不能为空', trigger: 'blur'}
                ],
                usage: [
                    {required: true, message: '用法不能为空', trigger: 'blur'}
                ],
                dosage:[
                    {require:true,message:'用量不能为空',trigger:'blur'}
                ],
                remark:[
                    {required:true,message:'功能主治不能为空',trigger:'blur'}
                ],
                attention: [
                    {required: true,message:'注意事项不能为空',trigger:'blur'}
                ]
            },
            drugEditRules:{

            },
            dialogDrugVisible: false,
            /*==========================药品管理模块return结束===========================================*/

            /*==========================预约管理模块return开始===========================================*/
            tableBookingData: [],//存储预约数据
            totalBooking: 0,//总条数
            pageSizeBooking: 5,//每页5条
            currentPageBooking: 1,//
            nickname:"",
            bookDoctorName:"",
            bookingIds:"",//批量删除的id
            /*==========================预约管理模块return结束===========================================*/
            /*===============================就诊记录模块return开始==========================================*/
            tableRecordData:[],
            totalRecord: 0,//总条数
            pageSizeRecord: 5,//每页5条
            currentPageRecord: 1,//
            RnickName:"",
            DocterName:"",
            recordIds:"",//批量删除预约记录的Id
            /*===============================就诊记录模块return结束==========================================*/

            /*==========================处方信息模块return开始===========================================*/
            editModalRecordVisible: false,
            editedRecord: {},
            tableRecipeData:[],
            totalRecipe: 0,//总条数
            pageSizeRecipe: 5,//每页5条
            currentPageRecipe: 1,//
            showRecipeCard:false,
            RecipeIds:"",
            showDureCard: false,
            durgList:[],
            totalOpenDrug: 0,//总条数
            pageSizeOpenDrug: 5,//每页5条
            currentPageOpenDrug: 1,//
            drugOpenName: "",
            showOpenDrug: true,
            recipeId: "",
            /*==========================处方信息模块return结束===========================================*/


            /*===============================留言反馈模块return开始==========================================*/
            editModalFeedBackVisible: false,
            editedFeed: {},
            editFeedRules:{
                replyContent:[
                    {required: true, message: '请输入回复内容', trigger: 'blur'},
                ]
            },
            tableFeedBackData:[],//留言反馈数据
            totalFeedBack: 0,//总条数
            pageSizeFeedBack: 5,//每页5条
            currentPageFeedBack: 1,//
            Theme:"",
            FNickName:"",
            feedbackIds:"",//批量删除预约记录的Id
            /*===============================留言反馈模块return结束==========================================*/


            /*========================公告信息模块return开始===================================*/
            tableNoticeData: [],//存储公告数据
            themeNotice: '',//公告主题字段---查询
            dialogNoticeVisible: false,//新增模态框关闭状态
            newNotice: {
                notice: '',
                issueTime: ''
            },
            totalNotice: 0,//总条数
            pageSizeNotice: 5,//每页5条
            currentPageNotice: 1,//
            editedNotice: {},
            editModalNoticeVisible: false,
            noticeRules:{
                notice:[
                    {required: true, message: '请输入主题', trigger: 'blur'},
                    {pattern: /^[a-zA-Z0-9_-]{4,20}$/, message: '用户名必须是4~20长度的字符组成', trigger: 'blur'}
                ],
                issueTime:[
                    {required: true, message: '发布日期不能为空', trigger: 'blur'},
                ]
            },
            /*==========================公告信息模块return结束=============================*/
        }
    },



    computed: {


        shouldShowAddButton() {
            // 遍历 ListSource 数组，检查每个元素的 status 属性
            for (let i = 0; i < this.ListSource.length; i++) {
                if (this.ListSource[i].status === 1) {
                    return false; // 如果有一个元素的状态为 1，则不显示新增按钮
                }
            }
            return true; // 如果所有元素的状态都不为 1，则显示新增按钮
        },
        switchValue() {
            const switchObj = {};
            this.tableDoctorData.forEach((doctor) => {
                switchObj[doctor.id] = doctor.status === 0;
            });
            return switchObj;
        },
        switchUserValue(){
            const switchUserObj = {};
            this.tableUserData.forEach((user) => {
                switchUserObj[user.id] = user.status === 0;
            });
            return switchUserObj;
        },
    },


    methods: {
        //判断用户是否有token
        checkToken(){
            console.log(0)
            if(localStorage.getItem("localJwt")===null){
                console.log("1")
                location.href="/login.html"
            }
        },

        handleCommandAV(command) {
            if (command == 'openEditInfoDialog') {
                this.openEditInfoDialog();
            } else if (command == 'openEditAvatarDialog') {
                this.openEditAvatarDialog();
            } else if (command == 'openEditPasswordDialog') {
                this.openEditPasswordDialog();
            } else if (command == 'openLogoutConfirm') {
                this.openLogoutConfirm();
            }
        },
        openEditInfoDialog() {
            console.log('准备弹出修改当前用户资料的对话框');
        },
        openEditAvatarDialog() {
            console.log('准备弹出修改当前用户头像的对话框');
        },
        openEditPasswordDialog() {
            console.log('准备弹出修改当前用户密码的对话框');
        },
        openLogoutConfirm() {
            let message = '您确定退出登录吗？';
            this.$confirm(message, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                localStorage.removeItem('localJwt');
                location.href="/index.html"/*返回主页*/
            }).catch(() => {
            });
        },
        loadCurrentUserInfo() {

            this.currentUserName = localStorage.getItem('currentUserName');
            this.currentUserAvatar = localStorage.getItem('currentUserAvatar');

        },
        handleMenuSelect(index) {
            this.selectedIndex = index;
            if(index==='2'){ /*点击用户信息模块，会传过来相对应的index的值*/
                this.showUserInfo();/*自定义showDoctorInfo，跳转到这个方法，发送请求给后端查询数据，渲染页面上*/
            }
            if(index==='3'){ /*点击医生信息模块，会传过来相对应的index的值*/
                this.showDoctorInfo();/*自定义showDoctorInfo，跳转到这个方法，发送请求给后端查询数据，渲染页面上*/
            }
            if(index==='4'){
                v.showEmpty = true;
                v.showSource = false;
                v.showAppointCard = false;
                v.showDoctorCard = false;
                v.showSourceCard = false;
                this.currentDoctorId = -1;
                this.currentAppointId = -1;
                this.showDeptInfo();
            }
            if(index==='5'){
                this.showDrugInfo();
            }
            if(index==='6'){
                this.showBookingInfo();
            }
            if (index==='7'){
                this.showRecordInfo();
            }
            if(index==='8'){
                this.showRecipeInfo();
                v.showRecipeCard=true;
                v.showDureCard = false;
            }
            if (index==='9'){
                this.showFeedBackInfo();
            }
            if (index==='10'){
                this.showNoticeInfo();
            }
            /*这里也是一样，写判断如果index==‘4’，查询相对应模块的index==4的所有信息*/
        },

        toggleSelection(rows) {
            if (rows) {
                rows.forEach(row => {
                    this.$refs.multipleTable.toggleRowSelection(row);
                });
            } else {
                this.clearSelection();
            }
        },
        clearSelection() {
            this.$refs.multipleTable.clearSelection();
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        /*=================================首页信息模块方法开始i========================================*/
        showIndexNotice(){
            axios.get("/pa/notice/selectIndexAll",{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(response=>{
                v.tableIndexNoticeData = response.data.data;
            })
        },

        fetchData(){
            axios.get("/pa/dept/getDeptDoctor",{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                }}).then(response => {
                const departmentData = response.data.data; // 接收到的集合数据
                // 处理接收到的集合数据，例如更新状态或渲染图表等
                console.log(departmentData); // 输出集合数据
                v.DeptNumDoctor = departmentData;
                const data = departmentData.map(item =>({
                    name:item.deptname,
                    value:item.num
                }));
                const legendData = departmentData.map(item => item.deptname);
                const colorData = [
                    '#ff0000', // 红色
                    '#0000ff', // 蓝色
                    '#00ff00', // 绿色
                    '#ffff00', // 黄色
                    '#000000', // 黑色
                    '#ffa500', // 橙色
                    '#800080', // 紫色
                    '#ff00ff', // 粉色
                ];
                this.renderChart(data, legendData, colorData);
            })
        },
        renderChart(data, legendData, colorData){
            this.$nextTick(() => {
                this.chart = echarts.init(document.getElementById('chart-container'));

                const option = {
                    title: {
                        text: '科室人数统计',
                        left: 'center'
                    },
                    tooltip: {
                        formatter: function(params) {
                            const deptName = params.name;
                            const num = params.value;
                            return `${deptName}: ${num}人`;
                        }
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        top: '5%', // 调整整个图例的位置，向下移动10%
                        data: legendData,
                        formatter: function(name) {
                            const index = legendData.indexOf(name);
                            const color = colorData[index];
                            return `{color|${name}}`;
                        },
                        textStyle: {
                            rich: {
                                color: {
                                    height: 12,
                                    width: 12,
                                    borderRadius: 6,
                                    display: 'inline-block',
                                    marginRight: 5,
                                    /* marginTop: 40 // 控制颜色向下的偏移量*/
                                }
                            }
                        }
                    },
                    series: [
                        {
                            name: '人数',
                            type: 'pie',
                            radius: '55%',
                            data: data.map(item => ({
                                name: item.name,
                                value: item.value
                            })),
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            },
                            label: {
                                position: 'outside',
                                formatter: function(params) {
                                    return params.name;
                                }
                            }
                        }
                    ]
                };

                this.chart.setOption(option);
            });
        },

        renderIncomeChart(){
            axios.get("/pa/users/month",{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                }}).then(response=>{
                //map的形式出传过来了
                const dataMap = response.data.data;
                const months = Object.keys(dataMap);//获取传过来的key值
                const incomes = Object.values(dataMap);//获取传过来的value值
                const chartDom = document.getElementById('income-chart');
                const myChart = echarts.init(chartDom)
                const option = {
                    title: {
                        text: '---每月预约人数统计图---', // 添加题目
                        textStyle: {
                            fontWeight: 'bold',
                            fontSize: 18
                        },
                        left: 'center',
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'line'
                        }
                    },
                    xAxis: {
                        type: 'category',
                        data: months
                    },
                    yAxis: {
                        type: 'value',
                        name: '人数'
                    },
                    series: [
                        {
                            data: incomes,
                            type: 'line',
                            smooth: true
                        }
                    ]
                };

                myChart.setOption(option);
            })
        },
        /*=================================首页信息模块方法结束=======================================*/

        /*===============================医生模块方法开始====================================*/
        deleteById(id){
            const currentPage = v.currentPage;
            axios.delete("/pa/doctor/deleteById/"+id,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(function (response) {
                if(response.data.code===1){
                    if (v.tableDoctorData.length === 1 && currentPage > 1) {
                        // 如果删除前是最后一页且只有一条数据，则返回上一页
                        v.$message.success("删除成功");
                        v.currentPage = currentPage - 1;
                        v.showDoctorInfo();//重新加载信息
                    }else {
                        v.$message.success("删除成功");
                        v.showDoctorInfo();//重新加载信息
                    }
                }else {
                    v.$message.error("删除失败")
                }
            })
        },
        handleSwitchChange(id){
            axios.get("/pa/doctor/changStatus/"+id,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(function (response) {
                console.log(response.data.data.status+"===")
                if(response.data.code==1){
                    if(response.data.data.status==1){
                        v.$message.error("禁用")
                        this.showDoctorInfo();
                    }else {
                        v.$message.success("启用")
                        this.showDoctorInfo();
                    }
                }
            }.bind(this))
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            v.pageSize = val; // 每次修改每页条数时，重置当前页数为第一页
            this.showDoctorInfo();
        },
        handleCurrentChange(page) {
            console.log("进来了jahhah")
            this.currentPage = page;
            this.showDoctorInfo();
        },
        showDoctorInfo() {//所有医生的基本信息
            console.log("哈哈啊啊哈哈")
            axios.get("/pa/doctor/selectAll?page=" + v.currentPage + "&pageSize=" + v.pageSize+"&no="+v.searchNo+"&nickName="+v.searchName,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(function (response) {
                if(response.data.code==1){
                    console.log(response.data.data.doctors+"===")
                    v.tableDoctorData = response.data.data.doctors;
                    v.total = response.data.data.total;
                }else {
                    v.$message.error("数据为空");
                }
            })
        },
        searchDoctors(){
            this.currentPage = 1;
            this.showDoctorInfo();
        },
        deleteSelection(){
            // 获取选中的医生信息的ID
            const selectedIds = this.multipleSelection.map((doctor) => doctor.id);
            if (selectedIds.length === 0) {
                this.$message.warning('请先选择要删除的医生信息');
                return;
            }
            v.ids = selectedIds;
            let data = v.ids
            const currentPage = v.currentPage;
            // 弹出确认删除的对话框
            this.$confirm('确认删除吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(()=>{
                axios.post("/pa/doctor/deleteByIds",data,{
                    headers: {'token': localStorage.getItem('localJwt')}}).then(response=> {//因为要重新加载医生信息，所以要回调，用=》
                    if(response.data.code===1){
                        if (v.tableDoctorData.length === 1 && currentPage > 1) {
                            // 如果删除前是最后一页且只有一条数据，则返回上一页
                            v.$message.success("删除成功");
                            v.currentPage = currentPage - 1;
                            v.showDoctorInfo();//重新加载信息
                        }else {
                            v.$message.success("删除成功");
                            v.showDoctorInfo();//重新加载信息
                        }
                    }else {
                        v.$message.error("删除失败");
                    }
                })
            }) .catch(() => {
                // 用户点击取消，不执行任何操作
            });
        },
        getDoctorById(id) {
            // 假设tableDoctorData是医生数据的数组
            return this.tableDoctorData.find(doctor => doctor.id === id);
        },
        editedById(id) {
            // 根据id获取医生对象，假设为getDoctorById方法
            const doctor = this.getDoctorById(id);
            if (doctor) {
                // 将当前行的数据复制到editedDoctor中
                this.editedDoctor = { ...doctor };
                console.log(v.editedDoctor.deptname+"====")
                this.editedDoctor.gender = String(doctor.gender); // 将整数类型转换为字符串类型
                this.editedDoctor.degree = String(doctor.degree);
                // 显示编辑模态框
                this.editModalVisible = true;
            }
        },
        submitEdit() {
            this.$refs.editForm.validate((valid) => {
                if(valid){
                    // 执行提交操作，例如更新医生数据
                    const updateDoctor ={
                        id:this.editedDoctor.id,
                        no:this.editedDoctor.no,
                        nickName:this.editedDoctor.nickName,
                        username:this.editedDoctor.username,
                        gender:this.editedDoctor.gender,
                        deptname:this.editedDoctor.deptname,
                        deptId:this.editedDoctor.deptId,
                        birthday:dayjs(this.editedDoctor.birthday).format('YYYY-MM-DD'),
                        phone:this.editedDoctor.phone,
                        email:this.editedDoctor.email,
                        degree:this.editedDoctor.degree,
                        joinTime:dayjs(this.editedDoctor.joinTime).format('YYYY-MM-DD'),
                        updateTime:dayjs(this.editedDoctor.updateTime).format('YYYY-MM-DD'),
                    }
                    /* v.deptId = v.deptname;//v.deptname里面装了deptId的值，赋值给他*/
                    v.editedDoctor = updateDoctor;
                    console.log(v.editedDoctor);
                    axios.put("/pa/doctor/updateById",v.editedDoctor,{
                        headers: {
                            'token': localStorage.getItem('localJwt'),
                            // 'Content-Type': 'application/json'
                        }}).then(response=>{
                        if(response.data.code===1){
                            v.tableDoctorData = response.data.data;
                            v.$message.success("更新成功");
                            // 隐藏编辑模态框
                            this.editModalVisible = false;
                            this.showDoctorInfo();
                        }
                    }) .catch(error => {
                        console.error('医生数据更新失败', error);
                    });
                }
            })
        },
        resetForm() {
            this.$refs.editForm.resetFields();
        },

        /*模态框新增医生信息*/
        showAddDialog(){
            this.newDoctor = {
                no: '',
                username: '',
                gender: '',
                deptname: '',
                birthday: '',
                phone: '',
                email: '',
                degree: '',
                joinTime: ''
            };
            this.dialogDoctorVisible = true; // 将模态框的可见性设置为true
        },
        /*关闭模态框，把数据都清空*/
        resetNewDoctor() {
            console.log("你好")
            v.newDoctor = {
                no: '',
                username: '',
                gender: '',
                deptname: '',
                birthday: '',
                phone: '',
                email: '',
                degree: '',
                joinTime: ''
            };
            v.$refs.newDoctorForm.resetFields();
        },
        addDoctor() {
            this.$refs.newDoctorForm.validate((valid) => {
                if (valid) {
                    // 执行提交逻辑
                    axios.post("/pa/doctor/addDoctor",v.newDoctor,{
                        headers: {
                            'token': localStorage.getItem('localJwt'),
                            // 'Content-Type': 'application/json'
                        }}).then(function (response) {
                        if(response.data.code===1){
                            v.$message.success("添加成功");
                            v.resetNewDoctor();
                            v.dialogDoctorVisible = false;
                            v.showDoctorInfo();
                        }else if(response.data.code===4001){
                            v.$message.error("工号已存在");
                        }
                    })
                }
            });
        },
        resetForm() {
            console.log("进来了")
            v.newDoctor = {
                no: '',
                username: '',
                gender: '',
                deptname: '',
                birthday: '',
                phone: '',
                email: '',
                degree: '',
                joinTime: ''
            };
        },
        getDepartments(){//获取科室数据
            axios.get("/pa/dept/selectDict",{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(function (response) {
                if(response.data.code===1){
                    v.departments = response.data.data;
                }
            })
        },
        /*===============================医生模块方法结束====================================*/

        /*===============================用户信息模块方法开始====================================*/
        getStatusTagType(status){
            if(status===0){
                return '';
            }else if(status===1){
                return 'danger';
            }else if(status===2){
                return 'success';
            }
        },
        getStatusLabel(status){
            if (status === 0) {
                return '已预约';
            } else if (status === 1) {
                return '已取消';
            } else if (status === 2) {
                return '已就诊';
            }
        },
        resetUserForm(){
            this.$refs.editUserForm.resetFields();
        },
        editedUserById(id){
            //根据id获取用户对象
            const user = this.getUserById(id);
            if(user){
                //将当前数据复制到editedUser中
                this.editedUser = {...user};
                this.editedUser.birthday = String(user.birthday);
                this.editedUser.gender = String(user.gender); // 将整数类型转换为字符串类型
                this.editModalUserVisible = true;
            }
        },
        getUserById(id){
            // tableUserData是医生数据的数组
            return this.tableUserData.find(user => user.id === id);
        },
        showRechargeModal(userId) {
            console.log(userId+"ppppp"+ userId);
            v.rechargeUserId = userId; // 将用户的 ID 存储起来
            v.showRechargeDialog = true; // 打开充值模态框
        },
        closeRechargeModal() {
            v.showRechargeDialog = false; // 关闭充值模态框
            v.rechargeUserId = null; // 清空充值用户的 ID
            v.rechargeAmount = null; // 重置充值金额
        },
        submitUserEdit(){
            this.$refs.editUserForm.validate((valid) => {
                if(valid){
                    // 执行提交操作，例如更新医生数据
                    const updateUser ={
                        id:this.editedUser.id,
                        username:this.editedUser.username,
                        gender:this.editedUser.gender,
                        birthday:dayjs(this.editedUser.birthday).format('YYYY-MM-DD'),
                        nickname:this.editedUser.nickname,
                        phone:this.editedUser.phone,
                        email:this.editedUser.email,
                        address:this.editedUser.address,
                        job:this.editedUser.job,
                        amount:this.editedUser.amount,
                        updateTime:dayjs(this.editedUser.updateTime).format('YYYY-MM-DD'),
                    }
                    /* v.deptId = v.deptname;//v.deptname里面装了deptId的值，赋值给他*/
                    v.editedUser = updateUser;
                    console.log(v.editedUser);
                    axios.put("/pa/users/updateById",v.editedUser,{
                        headers: {
                            'token': localStorage.getItem('localJwt'),
                            // 'Content-Type': 'application/json'
                        }}).then(response=>{
                        if(response.data.code===1){
                            v.tableUserData = response.data.data;
                            v.$message.success("更新成功");
                            // 隐藏编辑模态框
                            this.editModalUserVisible = false;
                            this.showUserInfo();
                        }
                    }) .catch(error => {
                        console.error('用户数据更新失败', error);
                    });
                }
            })
        },

        performRecharge() {
            // 获取充值用户的 ID 和充值金额
            const userId = v.rechargeUserId;
            const amount = v.rechargeAmount;
            if(amount==null){
                this.$message.error('请输入充值金额');
                return;
            }
            // 根据用户的 ID 和充值金额进行相关的业务逻辑处理
            axios.get("/pa/users/topUp?id="+userId+"&amount="+amount,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(response=>{
                if(response.data.code==1){
                    v.$message.success("充值成功")
                    this.showUserInfo();
                    this.renderIncomeChart();//刷新月收入统计图
                }
            })
            // 处理完成后关闭充值模态框
            this.closeRechargeModal();
        },

        handleSwitchUserChange(id){
            axios.get("/pa/users/changStatus/"+id,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }
            }).then(function (response) {
                if(response.data.code==1){
                    if(response.data.data.status==1){
                        v.$message.error("禁用")
                        this.showUserInfo();
                    }else {
                        v.$message.success("启用")
                        this.showUserInfo();
                    }
                }
            }.bind(this))
        },
        deleteUserById(id){
            const currentPageUser = v.currentPageUser; // 保存当前页码
            axios.delete("/pa/users/deleteById/"+id,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(function (response) {
                if(response.data.code===1){
                    if (v.tableUserData.length === 1 && currentPageUser > 1) {
                        // 如果删除前是最后一页且只有一条数据，则返回上一页
                        v.currentPageUser = currentPageUser - 1;
                        v.showUserInfo();//重新加载信息
                    }else {
                        v.showUserInfo();//重新加载信息
                    }

                    v.$message.success("删除成功")
                    v.showUserInfo();
                }else {
                    v.$message.error("删除失败")
                }
            })
        },

        handleSizeChangeUser(val) {
            console.log(`每页 ${val} 条`);
            v.pageSizeUser = val; // 每次修改每页条数时，重置当前页数为第一页
            this.showUserInfo();
        },
        handleCurrentChangeUser(page) {
            console.log("进来了jahhah")
            this.currentPageUser = page;
            this.showUserInfo();
        },
        showUserInfo(){//获取所有用户的信息
            console.log(v.searchStatus+"======")
            axios.get("/pa/users/selectAll"+"?page=" + v.currentPageUser + "&pageSize=" + v.pageSizeUser + "&status=" + v.searchStatus + "&username=" + v.searchUsername + "&nickname=" + v.searchNick, {
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }
            }).then(function (response) {
                if(response.data.code==1){
                    console.log(response.data.data.total+"======")
                    v.tableUserData = response.data.data.users;
                    v.totalUser = response.data.data.total;
                    if(v.searchStatus!=null){
                        v.searchStatus=""
                    }
                }else {
                    v.$message.error("数据为空");
                }
            })
        },
        searchUsers(){
            this.currentPage = 1;
            this.showUserInfo();
        },
        deleteUserSelection(){
            // 获取选中的用户信息的ID
            const selectedIds = this.multipleSelection.map((user) => user.id);
            if (selectedIds.length === 0) {
                this.$message.warning('请先选择要删除的用户信息');
                return;
            }
            v.ids = selectedIds;
            let data = v.ids
            console.log("ids:"+v.ids)
            const currentPageUser = v.currentPageUser; // 保存当前页码
            // 弹出确认删除的对话框
            this.$confirm('确认删除吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(()=>{
                axios.post("/pa/users/deleteByIds",data,{
                    headers: {'token': localStorage.getItem('localJwt')}}).then(response=> {//因为要重新加载用户信息，所以要回调，用=》
                    if(response.data.code===1){
                        v.$message.success("删除成功");
                        if (v.tableUserData.length === 1 && currentPageUser > 1) {
                            // 如果删除前是最后一页且只有一条数据，则返回上一页
                            v.currentPageUser = currentPageUser - 1;
                            v.showUserInfo();//重新加载信息
                        }else {
                            v.showUserInfo();//重新加载信息
                        }
                    }else {
                        v.$message.error("删除失败");
                    }
                })
            }) .catch(() => {
                // 用户点击取消，不执行任何操作
            });
        },
        /*===============================用户信息模块方法结束====================================*/

        /*==================================科室信息模块方法开始===================================*/
        // 自定义方法，过滤文字并添加换行
        // 将文字按照每20个字符分割为多行
        splitText(text, maxLength) {
            const lines = [];
            for (let i = 0; i < text.length; i += maxLength) {
                lines.push(text.slice(i, i + maxLength));
            }
            return lines;
        },
        showDeptInfo(){/*所有科室的信息*/
            v.showDeptCard = true
            console.log("就是这里")
            axios.get("/pa/dept/selectChild?page="+v.currentPageDept+"&pageSize="+v.pageSizeDept+"&deptname="+v.searchDeptName,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                }}).then(response=>{
                if(response.data.code===1){
                    console.log(response.data.data)
                    v.tableDeptData = response.data.data.depts;
                    v.totalDept = response.data.data.total;
                }
            })
        },
        searchDepts(){
            this.currentPageDept = 1;
            this.showDeptInfo();
        },
        findDoctors(){
            this.currentPageDeptAndDoctor = 1;
            this.selectDeptByIdFindDoctor1(v.deptId);
        },
        handleSizeChangeDept(val) {
            console.log(`每页 ${val} 条`);
            v.pageSizeDept = val; // 每次修改每页条数时，重置当前页数为第一页
            this.showDeptInfo();
        },
        handleCurrentChangeDept(page) {
            console.log("进来了jahhah")
            this.currentPageDept = page;
            this.showDeptInfo();
        },
        handleSizeChangeDeptAndDoctor(val) {
            console.log(`每页 ${val} 条`);
            v.pageSizeDeptAndDoctor = val; // 每次修改每页条数时，重置当前页数为第一页
            this.selectDeptByIdFindDoctor();
        },
        handleCurrentChangeAndDoctor(page) {
            console.log("进来了jahhah")
            this.currentPageDeptAndDoctor = page;
            this.selectDeptByIdFindDoctor();
        },


        handleSizeChangeDoctorAppoint(val) {
            console.log(`每页 ${val} 条`);
            v.pageSizeDeptAndDoctorAppoint = val; // 每次修改每页条数时，重置当前页数为第一页
            this.showSchedules(v.doctor);
        },
        handleCurrentChangeDoctorAppoint(page) {
            console.log("进来了jahhah")
            this.currentPageDeptAndDoctorAppoint = page;
            this.showSchedules(v.doctor);
        },
        deleteDeptSelection(){
            // 获取选中的用户信息的ID
            const selectedIds = this.multipleSelection.map((dept) => dept.id);
            if (selectedIds.length === 0) {
                this.$message.warning('请先选择要删除的用户信息');
                return;
            }
            v.ids = selectedIds;
            let data = v.ids;
            const currentPageDept = v.currentPageDept; // 保存当前页码
            console.log("当前页码："+currentPageDept)
            // 弹出确认删除的对话框
            this.$confirm('确认删除吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(()=>{
                axios.post("/pa/dept/deleteByIds",data,{
                    headers: {
                        'token': localStorage.getItem('localJwt'),
                        // 'Content-Type': 'application/json'
                    }}).then(response=> {//因为要重新加载用户信息，所以要回调，用=》
                    if(response.data.code===1){
                        v.$message.success("删除成功");
                        if (v.tableDeptData.length === 1 && currentPageDept > 1) {
                            // 如果删除前是最后一页且只有一条数据，则返回上一页
                            v.currentPageDept = currentPageDept - 1;
                            v.showDeptInfo(); // 重新加载信息
                        }else {
                            v.showDeptInfo(); // 重新加载信息
                        }
                    }else {
                        v.$message.error("删除失败");
                    }
                })
            }) .catch(() => {
                // 用户点击取消，不执行任何操作
            });
        },

        resetDeptForm(){//重置科室信息
            v.newDept = {
                deptremark: '',
            };
        },
        resetAppointForm(){//重置排班信息
            v.newAppoint = {
                schedulTime: '',
                sourceTotal: '',
                sourceSurplus: '',
            };
        },
        resetSourceForm(){//重置排班时间段信息
            v.newSource = {
                frameTime: '',
                endTime: '',
                sourceSurplus: '',
                sourceTotal: ''
            };
        },
        submitAppointEdit(){
            this.$refs.editAppointForm.validate((valid) => {
                if(v.editedAppoint.sourceTotal<v.editedAppoint.sourceSurplus){
                    v.$message.error("剩余号源不能大于号源总量")
                    return;
                }
                if(valid){
                    const updateAppoint = {
                        id:this.editedAppoint.id,
                        schedulTime:this.editedAppoint.schedulTime,
                        sourceTotal:this.editedAppoint.sourceTotal,
                        sourceSurplus:this.editedAppoint.sourceSurplus
                    }
                    v.editedAppoint = updateAppoint;
                    axios.put("/pa/appoint/updateById",v.editedAppoint,{
                        headers: {
                            'token': localStorage.getItem('localJwt'),
                            // 'Content-Type': 'application/json'
                        }}).then(response=>{
                        if(response.data.code===1){
                            v.tableAppointData = response.data.data;
                            v.$message.success("更新成功");
                            this.editModalAppointVisible = false;
                            this.showSchedules(v.doctor);
                        }else if(response.data.code===2002){
                            v.$message.success("操作失败");
                        }
                    }).catch(error =>{
                        console.error('排班数据更新失败',error)
                    })
                }
            })
        },
        submitDeptEdit(){
            this.$refs.editDeptForm.validate((valid) => {
                if(valid){
                    const updateDept = {
                        id:this.editedDept.id,
                        deptremark:this.editedDept.deptremark
                    }
                    console.log("id:"+this.editedDept.id)
                    v.editedDept = updateDept;
                    axios.put("/pa/dept/updateById",v.editedDept,{
                        headers: {
                            'token': localStorage.getItem('localJwt'),
                        }}).then(response=>{
                        if(response.data.code===1){
                            v.tableDeptData = response.data.data;
                            v.$message.success("更新成功");
                            this.editModalDeptVisible = false;
                            this.showDeptInfo();
                        }else if(response.data.code===2002){
                            v.$message.success("操作失败");
                        }
                    }).catch(error =>{
                        console.error('公告数据更新失败',error)
                    })
                }
            })
        },

        /*根据id删除科室*/
        deleteDeptById(id){
            const currentPageDept = v.currentPageDept;
            axios.delete("/pa/dept/deleteById/"+id,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(function (response) {
                if(response.data.code===1){
                    if (v.tableDeptData.length === 1 && currentPageDept > 1) {
                        // 如果删除前是最后一页且只有一条数据，则返回上一页
                        v.$message.success("删除成功");
                        v.currentPageDept = currentPageDept - 1;
                        v.showDeptInfo();//重新加载信息
                    }else {
                        v.$message.success("删除成功");
                        v.showDeptInfo();//重新加载信息
                    }
                }else {
                    v.$message.error("删除失败")
                }
            })
        },
        /*根据id编辑科室*/
        editedDeptById(id){
            const dept = this.getDeptById(id);
            if(dept){
                this.editedDept = {...dept};
                this.editModalDeptVisible = true;
            }
        },
        getDeptById(id){
            // tableNoticeData是公告数据的数组
            console.log("数据:"+this.tableDeptData.find(dept => dept.id === id))
            return this.tableDeptData.find(dept => dept.id === id);
        },
        /*根据id获取每个科室有多少医生*/
        selectDeptByIdFindDoctor(deptId){
            v.showEmpty = false;
            v.deptId = deptId;
            if (this.currentDoctorId === deptId) {
                console.log("医生来")
                // 点击已显示的按钮，隐藏卡片
                this.currentDoctorId = -1; // 更新为不存在的科室ID
                this.showDoctorCard = false;
                v.showEmpty = true;
            } else {
                console.log("医生否则来")
                setTimeout(() => {
                    v.loading = false; // 一秒后停止加载状态
                }, 1000);
                v.loading = true;
                axios.get("/pa/dept/selectByDeptId?page="+v.currentPageDeptAndDoctor+"&pageSize="+v.pageSizeDeptAndDoctor+"&deptId="+deptId+"&no="+v.no+"&nickName="+v.nickName,{
                    headers: {
                        'token': localStorage.getItem('localJwt'),
                        // 'Content-Type': 'application/json'
                    }}).then(response=>{
                    if(response.data.code===1){
                        console.log("条数:"+response.data.data.total)
                        v.ListDoctor = response.data.data.doctorList;
                        v.totalDeptAndDoctor =  response.data.data.total
                        v.currentDoctorId = deptId; // 更新当前科室ID
                    }
                })
                this.showDoctorCard = true;

            }
        },

        selectDeptByIdFindDoctor1(deptId){
            axios.get("/pa/dept/selectByDeptId?page="+v.currentPageDeptAndDoctor+"&pageSize="+v.pageSizeDeptAndDoctor+"&deptId="+deptId+"&no="+v.no+"&nickName="+v.nickName,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(response=>{
                if(response.data.code===1){
                    console.log("条数:"+response.data.data.total)
                    v.ListDoctor = response.data.data.doctorList;
                    v.totalDeptAndDoctor =  response.data.data.total
                }
            })
        },

        showSchedules(doctor){//点击号源显示这个医生的日排班信息
            v.showDeptCard = false;
            v.showDoctorCard = false;
            v.showAppointCard = true;
            v.showSource = true;
            v.showSourceCard =false;
            if(doctor.nickName!=null){
                v.currentDoctorName = doctor.nickName;
                v.currentDoctorNo = doctor.no;
            }
            if(v.searchDeptAppointDate!=null && v.searchDeptAppointDate!=''){
                console.log("过来了====="+doctor.nickName,":"+doctor.no);
                var formattedTime = v.searchDeptAppointDate.toLocaleString();
                v.searchDeptAppointDate = formattedTime;
                console.log( v.searchDeptAppointDate );
            }
            console.log("===="+v.currentDoctorNo);
            axios.get("/pa/dept/selectAppoint?page="+v.currentPageDeptAndDoctorAppoint+"&pageSize="+v.pageSizeDeptAndDoctorAppoint+"&no="+v.currentDoctorNo+"&schedulTime="+v.searchDeptAppointDate,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(response=>{
                v.tableAppointData = response.data.data.deptAppoint;
                v.totalDeptAndDoctorAppoint = response.data.data.total;
                v.searchDeptAppointDate = '';
                /*this.selectAppoint(v.newSource.appointId);*/
            })
        },
        goBack(){//点击返回图标
            v.showAppointCard = false;
            v.showDeptCard = true;
            v.showDoctorCard = true;
            v.showSource = false;
            v.showSourceCard =false;
        },
        //根据id删除日排班
        deleteAppointById(id){
            console.log("进来了哦")
            axios.delete("/pa/appoint/deleteById/"+id,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(response=>{
                if(response.data.code===1){
                    v.$message.success("删除成功");
                    v.showSchedules(v.doctor);
                }
            })
        },
        getAppointById(id){
            console.log("数据:"+this.tableAppointData.find(appoint => appoint.id === id))
            return this.tableAppointData.find(appoint => appoint.id === id);
        },
        //根据id编辑日排班
        editedAppointById(id){
            const appoint = this.getAppointById(id);
            if(appoint){
                this.editedAppoint = {...appoint};
                this.editModalAppointVisible = true;
            }
        },
        updateSelection(){
            // 获取选中的医生信息的ID
            const selectedIds = this.multipleSelection.map((appoint) => appoint.id);
            if (selectedIds.length === 0) {
                this.$message.warning('请先选择要发布的医生排班');
                return;
            }
            v.ids = selectedIds;
            // 弹出确认删除的对话框
            this.$confirm('确认发布吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(()=>{
                axios.put("/pa/appoint/updateByIds",{ data: v.ids },{
                    headers: {
                        'token': localStorage.getItem('localJwt'),
                        // 'Content-Type': 'application/json'
                    }}).then(response=> {//因为要重新加载医生信息，所以要回调，用=》
                    if(response.data.code===1){
                        v.$message.success("发布成功");
                        /* v.showSourceCard =false;*/
                        v.showSchedules(v.doctor);//重新加载信息
                    }else {
                        v.$message.error("发布失败");
                    }
                })
            }) .catch(() => {
                // 用户点击取消，不执行任何操作
            });
        },
        showAddSource(){
            this.newSource = {
                frameTime: '',
                endTime: '',
                sourceSurplus: '',
                sourceTotal: ''
            };
            this.dialogSourceVisible = true; // 将模态框的可见性设置为true
        },
        showAddAppoint(){
            this.newAppoint = {
                schedulTime: '',
                sourceTotal: '',
                sourceSurplus: '',
            };
            this.dialogAppointVisible = true; // 将模态框的可见性设置为true
        },
        /*关闭模态框，把数据都清空*/
        resetNewAppoint() {
            v.newAppoint = {
                schedulTime: '',
                sourceTotal: '',
                sourceSurplus: '',
            };
            v.$refs.newAppointForm.resetFields();
        },
        addSource(){
            this.$refs.newSourceForm.validate((valid) => {
                if (valid) {
                    const frameTime = v.newSource.frameTime
                    const endTime = v.newSource.endTime
                    const sourceTotal = v.newSource.sourceTotal
                    const sumSourceTotal = parseInt(sourceTotal)+v.sourceTotal;//原有的时间段排班累加的和输入框添加的只和
                    console.log("输入框输入的:"+sourceTotal)
                    console.log("累加的："+v.sourceTotal)
                    console.log("累加sum的："+sumSourceTotal)
                    console.log("不是输入的:"+v.appointTotal)
                    const sourceSurplus = v.newSource.sourceSurplus
                    if(sumSourceTotal>v.appointTotal){
                        v.$message.error('添加的时间段号源总量超过了当天的号源总量')
                        return;
                    }
                    if(v.sourceTotal==v.appointTotal){
                        v.$message.error('当天的号源总量已全部排完,不能再添加')
                        return;
                    }
                    if(frameTime==='' || endTime===''){
                        v.$message.error('起始时间和结束时间不能为空')
                        return;
                    }else if(frameTime && endTime && frameTime >= endTime){
                        v.$message.error('起始时间必须早于结束时间')
                        return;
                    }else if(sourceTotal>v.appointTotal){
                        v.$message.error('号源总量不能超过'+v.appointTotal+"个")
                        return;
                    }/*else if(sourceSurplus>v.sourceSurplus){
                        v.$message.error('剩余号源不能大超过'+v.sourceSurplus+"个")
                        return;
                    }*/else if(sourceTotal<sourceSurplus){
                        v.$message.error('剩余号源不能超过号源总量')
                        return;
                    }else if(sourceTotal==v.sourceTotal){
                        v.$message.error('当天的号源总量已全部排完,不能再添加')
                        return;
                    }
                    console.log(v.AppointId);
                    v.newSource.appointId = v.AppointId;
                    console.log("AppointId:"+v.newSource.appointId)
                    axios.post("/pa/source/addSource",v.newSource,{
                        headers: {
                            'token': localStorage.getItem('localJwt'),
                        }}).then(response=>{
                        if(response.data.code==1){
                            v.$message.success("添加成功");
                            v.dialogSourceVisible = false;
                            /*this.selectAppointByIdFindSource(v.newSource.appointId);*/
                            this.selectAppoint(v.newSource.appointId);
                        }
                    })
                }
            });
        },
        selectAppoint(appointId){
            axios.get("/pa/source/selectAppoint?id="+appointId,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(response=>{
                if(response.data.code==1){
                    v.ListSource = response.data.data;
                }
            })
        },
        addAppoint(){
            this.$refs.newAppointForm.validate((valid) => {
                if (valid) {
                    if(v.newAppoint.sourceTotal<v.newAppoint.sourceSurplus){
                        v.$message.error("剩余号源不能大于号源总量")
                        return;
                    }
                    v.newAppoint.doctorNo = v.currentDoctorNo;
                    // 执行提交逻辑
                    axios.post("/pa/appoint/addAppoint",v.newAppoint,{
                        headers: {
                            'token': localStorage.getItem('localJwt'),
                            // 'Content-Type': 'application/json'
                        }}).then(function (response) {
                        if(response.data.code===1){
                            v.$message.success("添加成功");
                            v.resetNewAppoint();
                            v.dialogAppointVisible = false;
                            v.showSchedules(v.doctor);
                        }else if(response.data.code===4002){
                            v.$message.error(response.data.msg);
                        }
                    })
                }
            });
        },
        //点击日排班号源，根据id渲染时间段数据
        selectAppointByIdFindSource(AppointId){
            v.showSource = false;
            v.AppointId = AppointId;
            if (this.currentAppointId === AppointId) {
                // 点击已显示的按钮，隐藏卡片
                this.showSourceCard = false;
                this.currentAppointId = -1; // 更新为不存在的科室ID
                v.showSource = true;
            } else {
                console.log("否则来")
                setTimeout(() => {
                    v.loadingSource = false; // 一秒后停止加载状态
                }, 1000);
                v.loadingSource = true;
                axios.get("/pa/source/selectByAppointId?id="+AppointId,{
                    headers: {
                        'token': localStorage.getItem('localJwt'),
                        // 'Content-Type': 'application/json'
                    }}).then(response=>{
                    if(response.data.code===1){
                        v.ListSource = response.data.data;
                        v.currentAppointId = AppointId; // 更新当前科室ID
                        v.AppointSurplus = response.data.data.appointSurplus;
                        v.AppointTotal = response.data.data.appointTotal;
                        console.log(response.data.data.appointSurplus+"==="+response.data.appointSurplus)
                        console.log(response.data.data); // 输出整个对象

                        let sourceTotal = 0; // 累加变量
                        let sourceSurplus = 0; // 累加变量
                        // 循环遍历数据并取出某一个数据
                        response.data.data.forEach(item => {
                            const appointTotal = item.appointTotal;
                            const appointSurplus = item.appointSurplus;
                            v.appointTotal = appointTotal;
                            v.appointSurplus = appointSurplus;
                            sourceTotal += item.sourceTotal; // 累加 sourceTotal
                            sourceSurplus += item.sourceSurplus; // 累加 sourceSurplus
                        });
                        v.sourceTotal = sourceTotal; // 将累加结果赋值给 sourceTotal
                        v.sourceSurplus = sourceSurplus; // 将累加结果赋值给 sourceSurplus
                        console.log("当天排班的号源总量:"+ v.appointTotal)
                        console.log("每个时间段累加的总号源:"+ v.sourceTotal)
                    }
                })
                this.showSourceCard = true;
            }
        },
        /*==================================科室信息模块方法结束===================================*/

        /*==================================药品管理模块方法开始======================================*/
        handleSizeChangeDrug(val) {
            console.log(`每页 ${val} 条`);
            v.pageSizeDrug = val; // 每次修改每页条数时，重置当前页数为第一页
            this.showDrugInfo();
        },
        handleCurrentChangeDrug(page) {
            console.log("进来了======")
            this.currentPageDrug = page;
            this.showDrugInfo();
        },
        searchDrug(){
            this.currentPageDrug = 1;
            this.showDrugInfo();
        },
        showDrugInfo() {
            console.log('进入药品信息')
            //所有药品的基本信息
            const drugLike={
                page:v.currentPageDrug,
                pageSize:v.pageSizeDrug,
                drugNo:v.drugNo,
                drugName:v.drugName
            }
            axios.post("/pa/drug/selectAll",drugLike,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(function (response) {
                if(response.data.code==1){
                    v.tableDrugData = response.data.data.drugs;
                    v.totalDrug = response.data.data.total;
                    v.drugNo = '';
                    v.drugName = '';
                }else {
                    v.$message.error("数据为空");
                }
            })
        },

        deleteDrugById(id){
            const currentPageDrug = v.currentPageDrug; //获取当前页
            axios.delete("/pa/drug/deleteDrugId/"+id,{
                headers: {'token': localStorage.getItem('localJwt')}}).then(function (response) {
                if(response.data.code===1){
                    v.$message.success("删除成功")
                    if (v.tableDrugData.length === 1 && currentPageDrug > 1) {
                        // 如果删除前是最后一页且只有一条数据，则返回上一页
                        v.currentPageDrug = currentPageDrug - 1;
                        v.showDrugInfo();//重新加载信息
                    }else {
                        v.showDrugInfo();//重新加载信息
                    }
                }else {
                    v.$message.error("删除失败")
                }
            })
        },
        showAddDrug(){
            this.newDrug = {
                id: '',
                drugNo: '',
                drugName: '',
                inventory: '',
                unitprice: '',
                unit: '',
                usage: '',
                dosage:'',
                remark: '',
                attention:''
            };
            this.dialogDrugVisible = true; // 将模态框的可见性设置为true
        },
        /*关闭模态框，把数据都清空*/
        resetNewDrug() {
            v.newDrug = {
                id: '',
                drugNo: '',
                drugName: '',
                inventory: '',
                unitprice: '',
                unit: '',
                usage: '',
                dosage:'',
                remark: '',
                attention:''
            };
            v.$refs.newDrugForm.resetFields();
        },
        /*关闭模态框，把数据都清空*/
        resetShowDrug() {
            v.showDrug = {
                id: '',
                drugNo: '',
                drugName: '',
                inventory: '',
                unitprice: '',
                unit: '',
                usage: '',
                dosage:'',
                remark: '',
                attention:''
            };
            v.$refs.showDrugForm.resetFields();
        },

        resetDrugForm(){//重置药品信息
            v.newDrug = {
                id: '',
                drugNo: '',
                drugName: '',
                inventory: '',
                unitprice: '',
                unit: '',
                usage: '',
                dosage:'',
                remark: '',
                attention:''
            };
        },
        addDrug() {
            this.$refs.newDrugForm.validate((valid) => {
                if (valid) {
                    // 执行提交逻辑
                    console.log("kakskajdk"+v.newDrug.drugName)
                    axios.post("/pa/drug/addDrug",v.newDrug,{
                        headers: {
                            'token': localStorage.getItem('localJwt'),
                            // 'Content-Type': 'application/json'
                        }}).then(function (response) {
                        if(response.data.code===1){
                            v.$message.success("添加成功");
                            v.resetNewDrug();
                            v.dialogDrugVisible = false;
                            v.showDrugInfo();
                        }
                    })
                }
            });
        },
        getDrugById(id){
            // tableDrugData是药品数据的数组
            return this.tableDrugData.find(drug => drug.id === id);
        },
        editDurg(id){
            const drug = this.getDrugById(id);
            if(drug){
                this.editedDrug = {...drug};
                console.log("------"+this.editedDrug)
                this.editModalDrugVisible = true;
            }
        },
        showDurg(id){
            const drug = this.getDrugById(id);
            if(drug){
                this.showDrug = {...drug};
                this.showModalDrugVisible = true;
                console.log("********"+this.showDrug)
            }
        },

        submitDrugEdit(){
            this.$refs.editDrugForm.validate((valid) => {
                if(valid){
                    const updateDrug = {
                        id:this.editedDrug.id,
                        drugNo:this.editedDrug.drugNo,
                        drugName:this.editedDrug.drugName,
                        inventory:this.editedDrug.inventory,
                        unitprice:this.editedDrug.unitprice,
                        unit:this.editedDrug.unit,
                        usage:this.editedDrug.usage,
                        remark:this.editedDrug.remark,
                        dosage:this.editedDrug.dosage,
                        attention:this.editedDrug.attention
                    };
                    v.editedDrug = updateDrug;
                    console.log("=========="+v.editedDrug)
                    axios.put("/pa/drug/updateById",v.editedDrug,{
                        headers: {
                            'token': localStorage.getItem('localJwt'),
                            // 'Content-Type': 'application/json'
                        }}).then(response=>{
                        if(response.data.code===1){
                            v.tableDrugData = response.data.data;
                            v.$message.success("更新成功");
                            this.editModalDrugVisible = false;
                            this.showDrugInfo();
                        }
                    }).catch(error =>{
                        console.error('药品数据更新失败',error)
                    })
                }
            });
        },
        /*==================================药品管理模块方法结束======================================*/

        /*==================================预约管理模块方法开始======================================*/
        showBookingInfo() {
            //所有预约的基本信息
            console.log('进入药品信息')
            //所有药品的基本信息
            const bookingLike={
                page:v.currentPageBooking,
                pageSize:v.pageSizeBooking,
                nickname:v.nickname,//预约人
                bookDoctorName:v.bookDoctorName,//医生名称
            }
            axios.post("/pa/booking/selectAll",bookingLike,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(function (response) {
                if(response.data.code==1){
                    v.tableBookingData = response.data.data.booking;
                    v.totalBooking = response.data.data.total;
                }else {
                    v.$message.error("数据为空");
                }
            })
        },
        handleSizeChangeBooking(val) {
            console.log(`每页 ${val} 条`);
            v.pageSizeBooking = val; // 每次修改每页条数时，重置当前页数为第一页
            this.showBookingInfo();
        },
        handleCurrentChangeBooking(page) {
            console.log("进来了jahhah")
            this.currentPageBooking = page;
            this.showBookingInfo();
        },
        cancelBooking(id){
            axios.get("/pa/booking/updateByIdStatus/"+id,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(function (response) {
                if(response.data.code==1){
                    v.$message.success("取消成功")
                    v.showBookingInfo();
                }else if(response.data.code==4003){
                    v.$message.success(response.data.msg)
                }else {
                    v.$message.success(response.data.msg)
                }
            })
        },
        deleteBookingSelection(){
            // 获取选中的用户信息的ID
            const selectedIds = this.multipleSelection.map((booking) => booking.id);
            if (selectedIds.length === 0) {
                this.$message.warning('请先选择要删除的预约信息');
                return;
            }
            console.log("ids="+selectedIds)
            v.bookingIds = selectedIds;
            let data = v.bookingIds
            const currentPageBooking = v.currentPageBooking; // 保存当前页码
            // 弹出确认删除的对话框
            this.$confirm('确认删除吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(()=>{
                axios.post("/pa/booking/deleteByIds",data,{
                    headers: {
                        'token': localStorage.getItem('localJwt'),
                        // 'Content-Type': 'application/json'
                    }}).then(response=> {//因为要重新加载预约信息，所以要回调，用=》
                    if(response.data.code===1){
                        v.$message.success("删除成功");
                        if (v.tableBookingData.length === 1 && currentPageBooking > 1) {
                            // 如果删除前是最后一页且只有一条数据，则返回上一页
                            v.currentPageBooking = currentPageBooking - 1;
                            v.showBookingInfo();//重新加载信息
                        }else {
                            v.showBookingInfo();//重新加载信息
                        }
                    }else {
                        v.$message.error("删除失败");
                    }
                })
            }) .catch(() => {
                // 用户点击取消，不执行任何操作
            });
        },
        searchBooking(){
            this.currentPageBooking = 1;
            this.showBookingInfo();
        },
        /*==================================预约管理模块方法结束======================================*/

        /*==================================就诊记录管理模块方法开始==================================*/

        searchAdminRecord(){
            this.currentPageRecord = 1;
            this.showRecordInfo();
        },
        showRecordInfo(){
            console.log("v.RnickName="+v.RnickName)
            console.log("v.DocterName="+v.DocterName)
            //当前医生的患者的基本信息
            const bookingLike={
                page:v.currentPageRecord,
                pageSize:v.pageSizeRecord,
                nickName:v.RnickName,//预约人
                doctorName:v.DocterName,//医生
            }
            axios.post("/pa/recipe/selectAdminAll",bookingLike,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }
            }).then(function (response) {
                if(response.data.code==1){
                    v.tableRecordData = response.data.data.record;
                    v.totalRecord = response.data.data.total;
                }else {
                    v.$message.error("数据为空");
                }
            })
        },
        handleSizeChangeRecord(val) {
            console.log(`每页 ${val} 条`);
            v.pageSizeRecord = val; // 每次修改每页条数时，重置当前页数为第一页
            this.showRecordInfo();
        },
        handleCurrentChangeRecord(page) {
            console.log("进来了jahhah")
            this.currentPageRecord = page;
            this.showRecordInfo();
        },
        deleteRecord(id){
            console.log("进来了")
            const currentPageRecord = v.currentPageRecord; // 保存当前页码
            axios.delete("/pa/recipe/deleteById/"+id,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }
            }).then(response=>{
                if(response.data.code===1){
                    if (v.tableRecordData.length === 1 && currentPageRecord > 1) {
                        // 如果删除前是最后一页且只有一条数据，则返回上一页
                        v.currentPageRecord = currentPageRecord - 1;
                        v.showRecordInfo();//重新加载信息
                    }else {
                        v.showRecordInfo();//重新加载信息
                    }

                    v.$message.success("删除成功")
                    v.showRecordInfo();
                }else {
                    v.$message.error("删除失败")
                }
            });
        },
        deleteAllRecord(){
            //获取选中的用户信息ID
            const  selectedIds = this.multipleSelection.map((recordList) => recordList.id);
            if (selectedIds.length===0){
                this.$message.warning('请选择要删除的记录信息');
                return;
            }
            console.log("ids="+selectedIds)
            v.recordIds = selectedIds;

            const currentPageRecord = v.currentPageRecord;//保存当前页码
            //弹出确认删除的对话框
            this.$confirm('确认删除吗？','提示',{
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(()=>{
                axios.delete("/pa/recipe/deleteByIds",{data: v.recordIds},{
                    headers:{
                        'token': localStorage.getItem('localJwt'),
                    }
                }).then(response=>{
                    if (response.data.code===1){
                        v.$message.success('删除成功');
                        if (v.tableRecordData.length===1&&currentPageRecord>1){
                            //如果删除前是最后一页且只有一条数据,则返回上一页
                            v.currentPageRecord = currentPageRecord-1;
                            v.showRecordInfo();//重新加载信息
                        }else {
                            v.showRecordInfo();//重新加载信息
                        }
                    }else {
                        v.$message.error('删除失败')
                    }
                })
            }).catch(()=>{
                //用户点击取消，不执行任何操作
            })
        },
        /*==================================就诊记录管理模块方法结束==================================*/

        /*=====================================处方信息方法开始============================================*/
        showRecipeInfo(){
            console.log("v.nickName"+v.nickName);
            const recipeLike={
                page:v.currentPageRecipe,
                pageSize:v.pageSizeRecipe,
                nickName:v.nickName,//预约人
            }
            axios.post("/pa/recipe/selectAdminRecipeAll",recipeLike,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                }
            }).then(function (response) {
                if(response.data.code==1){
                    // v.tableRecipeData = response.data.data.recipe;
                    v.totalRecipe = response.data.data.total;
                    v.tableRecipeData = response.data.data.recipe.map((item) => ({
                        ...item,
                        disabled: false,
                    }));
                    console.log(v.tableRecipeData);
                }else {
                    v.$message.error("数据为空");
                }
            })
        },
        searchDoctorRecipe(){
            this.currentPageRecipe=1;
            this.showRecipeInfo();
        },
        handleSizeChangeRecipe(val) {
            console.log(`每页 ${val} 条`);
            v.pageSizeRecipe = val; // 每次修改每页条数时，重置当前页数为第一页
            this.showRecipeInfo();
        },
        handleCurrentChangeRecipe(page) {
            console.log("进来了jahhah")
            this.currentPageRecipe = page;
            this.showRecipeInfo();
        },
        getRecordById(id){
            return this.tableRecordData.find(record => record.id === id);
        },
        resetRecipeForm(){//重置症状信息
            v.newRecipe = {
                schedulTime: '',
                announcements: '',
            };
        },
        queryOpenDrug(id){//点击配药查询该患者的配药情况
            v.recipeId = id
            console.log("进来看"+id)
            v.showOpenDrug = false
            v.showDureCard = true;
            axios.get("/pa/recipe/selectAdminOpenDrug?page="+v.currentPageOpenDrug+"&pageSize="+v.pageSizeOpenDrug+"&id="+id,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                }
            }).then(response=>{
                if(response.data.code===1){
                    console.log(response.data.data.openDrugs)
                    v.durgList = response.data.data.openDrugs;
                    v.totalOpenDrug = response.data.data.total;
                }
            })
        },
        AdminDeleteRecipe(id){//删除处方信息
            console.log("进来了*******"+id)
            const currentPageRecipe = v.currentPageRecipe; // 保存当前页码
            axios.delete("/pa/recipe/deleteAdminRecipeById/"+id,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                }
            }).then(response=>{
                if(response.data.code===1){
                    if (v.tableRecipeData.length === 1 && currentPageRecipe > 1) {
                        // 如果删除前是最后一页且只有一条数据，则返回上一页
                        v.currentPageRecipe = currentPageRecipe - 1;
                        v.showRecipeInfo();//重新加载信息
                    }else {
                        v.showRecipeInfo();//重新加载信息
                    }
                    v.$message.success("删除成功")
                    v.showRecipeInfo();
                }else {
                    v.$message.error("删除失败")
                }
            });
        },
        getOpenDrugById(id){
            console.log("数据:"+this.durgList.find(openDrug => openDrug.id === id))
            return this.durgList.find(openDrug => openDrug.id === id);
        },
        handleSizeChangeOpenDrug(val) {
            console.log(`每页 ${val} 条`);
            v.pageSizeOpenDrug = val; // 每次修改每页条数时，重置当前页数为第一页
            this.queryOpenDrug();
        },
        handleCurrentChangeOpenDrug(page) {
            console.log("进来了jahhah")
            this.currentPageOpenDrug = page;
            this.queryOpenDrug();
        },

        /*==================================处方信息模块结束==================================*/


        /*==================================留言反馈模块开始==================================*/
        searchAdminFeedBack(){
            this.currentPageFeedBack = 1;
            this.showFeedBackInfo();
        },
        showFeedBackInfo(){
            console.log("v.Theme="+v.Theme)
            console.log("v.FNickName="+v.FNickName)
            //当前留言反馈基本信息
            const feedbackLike={
                page:v.currentPageFeedBack,
                pageSize:v.pageSizeFeedBack,
                theme:v.Theme,//主题
                nickName:v.FNickName,//留言人名字
            }
            axios.post("/pa/feedback/selectAll",feedbackLike,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }
            }).then(function (response) {
                if(response.data.code==1){
                    v.tableFeedBackData = response.data.data.feedBack;
                    console.log(response.data)
                    v.totalFeedBack = response.data.data.total;
                }else {
                    v.$message.error("数据为空");
                }
            })
        },
        handleSizeChangeFeedBack(val) {
            console.log(`每页 ${val} 条`);
            v.pageSizeFeedBack = val; // 每次修改每页条数时，重置当前页数为第一页
            this.showFeedBackInfo();
        },
        handleCurrentChangeFeedBack(page) {
            console.log("进来了jahhah")
            this.currentPageFeedBack = page;
            this.showFeedBackInfo();
        },
        deleteFeedBack(id){
            console.log("进来了")
            const currentPageFeedBack = v.currentPageFeedBack; // 保存当前页码
            axios.delete("/pa/feedback/deleteById/"+id,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }
            }).then(response=>{
                if(response.data.code===1){
                    if (v.tableFeedBackData.length === 1 && currentPageFeedBack > 1) {
                        // 如果删除前是最后一页且只有一条数据，则返回上一页
                        v.currentPageFeedBack = currentPageFeedBack - 1;
                        v.showFeedBackInfo();//重新加载信息
                    }else {
                        v.showFeedBackInfo();//重新加载信息
                    }
                    v.$message.success("删除成功")
                    v.showFeedBackInfo();
                }else {
                    v.$message.error("删除失败")
                }
            });
        },
        deleteAllFeedBack(){
            //获取选中的用户信息ID
            const  selectedIds = this.multipleSelection.map((feedBackList) => feedBackList.id);
            if (selectedIds.length===0){
                this.$message.warning('请选择要删除的记录信息');
                return;
            }
            console.log("ids="+selectedIds)
            v.feedbackIds = selectedIds;

            const currentPageFeedBack = v.currentPageFeedBack;//保存当前页码
            //弹出确认删除的对话框
            this.$confirm('确认删除吗？','提示',{
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(()=>{
                axios.delete("/pa/feedback/deleteByIds",{data: v.feedbackIds},{
                    headers:{
                        'token': localStorage.getItem('localJwt'),
                    }
                }).then(response=>{
                    if (response.data.code===1){
                        v.$message.success('删除成功');
                        if (v.tableFeedBackData.length===1&&currentPageFeedBack>1){
                            //如果删除前是最后一页且只有一条数据,则返回上一页
                            v.currentPageFeedBack = currentPageFeedBack-1;
                            v.showFeedBackInfo();//重新加载信息
                        }else {
                            v.showFeedBackInfo();//重新加载信息
                        }
                    }else {
                        v.$message.error('删除失败')
                    }
                })
            }).catch(()=>{
                //用户点击取消，不执行任何操作
            })
        },
        getFeedBackById(id){
            return this.tableFeedBackData.find(record => record.id === id);
        },
        resetFeedBackForm(){//重置回复信息
            v.newFeedBack = {
                replyContent: '',
            };
        },
        feedReply(id){//回复
            const feed = this.getFeedBackById(id);
            if(feed){
                console.log("打开")
                this.editedFeed = {...feed};
                this.editModalFeedBackVisible = true;
            }
        },
        submitFeedBackEdit(){
            this.$refs.editFeedBackForm.validate((valid) => {
                if(valid) {
                    const updateFeedBack = {
                        replyContent:this.editedFeed.replyContent,
                        id:this.editedFeed.id

                    }
                    console.log("replyContent="+updateFeedBack.replyContent)
                    v.editedFeed = updateFeedBack;
                    axios.post("/pa/feedback/updateById",v.editedFeed,{
                        headers: {
                            'token': localStorage.getItem('localJwt'),
                            //'Content-Type': 'application/json'
                        }
                    }).then(response=>{
                        if(response.data.code===1){
                            v.$message.success("回复完成");
                            this.editModalFeedBackVisible = false;
                            this.showFeedBackInfo();
                        }
                    }).catch(error =>{
                        console.error('回复失败',error)
                    })
                }
            })
        },
        /*==================================留言反馈模块结束==================================*/

        /*===============================公告信息模块方法开始====================================*/
        showNoticeInfo() {

            //所有公告的基本信息
            console.log(v.themeNotice+"====")
            axios.get("/pa/notice/selectAll?page="+v.currentPageNotice+"&pageSize="+v.pageSizeNotice+"&notice="+v.themeNotice,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(function (response) {
                if(response.data.code==1){
                    v.tableNoticeData = response.data.data.notices;
                    v.totalNotice = response.data.data.total;
                }else {
                    v.$message.error("数据为空");
                }
            })
        },
        searchNotice(){
            this.currentPage = 1;
            this.showNoticeInfo();
        },
        handleSizeChangeNotice(val) {
            console.log(`每页 ${val} 条`);
            v.pageSizeNotice = val; // 每次修改每页条数时，重置当前页数为第一页
            this.showNoticeInfo();
        },
        handleCurrentChangeNotice(page) {
            console.log("进来了jahhah")
            this.currentPageNotice = page;
            this.showNoticeInfo();
        },
        deleteNoticeSelection(){
            // 获取选中的医生信息的ID
            const selectedIds = this.multipleSelection.map((notice) => notice.id);
            if (selectedIds.length === 0) {
                this.$message.warning('请先选择要删除的公告信息');
                return;
            }
            v.ids = selectedIds;
            const currentPageNotice = v.currentPageNotice; //获取当前页
            // 弹出确认删除的对话框
            this.$confirm('确认删除吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(()=>{
                axios.delete("/pa/notice/deleteByIds",{ data: v.ids },{
                    headers: {
                        'token': localStorage.getItem('localJwt'),
                        // 'Content-Type': 'application/json'
                    }}).then(response=> {//因为要重新加载医生信息，所以要回调，用=》
                    if(response.data.code===1){
                        if (v.tableNoticeData.length === 1 && currentPageNotice > 1) {
                            // 如果删除前是最后一页且只有一条数据，则返回上一页
                            v.$message.success("删除成功");
                            v.currentPageNotice = currentPageNotice - 1;
                            v.showNoticeInfo();//重新加载信息
                        }else {
                            v.$message.success("删除成功");
                            v.showNoticeInfo();//重新加载信息
                        }
                    }else {
                        v.$message.error("删除失败");
                    }
                })
            }) .catch(() => {
                // 用户点击取消，不执行任何操作
            });
        },
        deleteNoticeById(id){
            const currentPageNotice = v.currentPageNotice; //获取当前页
            axios.delete("/pa/notice/deleteNoticeId/"+id,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(function (response) {
                if(response.data.code===1){
                    v.$message.success("删除成功")
                    if (v.tableNoticeData.length === 1 && currentPageNotice > 1) {
                        // 如果删除前是最后一页且只有一条数据，则返回上一页
                        v.currentPageNotice = currentPageNotice - 1;
                        v.showNoticeInfo();//重新加载信息
                        v.showIndexNotice();
                    }else {
                        v.showNoticeInfo();//重新加载信息
                        v.showIndexNotice();
                    }
                }else {
                    v.$message.error("删除失败")
                }
            })
        },
        submitNoticeEdit(){
            const updateNotice = {
                id:this.editedNotice.id,
                notice:this.editedNotice.notice
            }
            v.editedNotice = updateNotice;
            axios.put("/pa/notice/updateById",v.editedNotice,{
                headers: {
                    'token': localStorage.getItem('localJwt'),
                    // 'Content-Type': 'application/json'
                }}).then(response=>{
                if(response.data.code===1){
                    v.tableNoticeData = response.data.data;
                    v.$message.success("更新成功");
                    this.editModalNoticeVisible = false;
                    this.showNoticeInfo();
                }
            }).catch(error =>{
                console.error('公告数据更新失败',error)
            })
        },
        showAddNotice(){
            this.newNotice = {
                id: '',
                notice: '',
                issueTime: '',
            };
            this.dialogNoticeVisible = true; // 将模态框的可见性设置为true
        },
        /*关闭模态框，把数据都清空*/
        resetNewNotice() {
            v.newNotice = {
                notice: '',
                issueTime: '',
            };
            v.$refs.newNoticeForm.resetFields();
        },
        editNotice(id){
            const notice = this.getNoticeById(id);
            if(notice){
                this.editedNotice = {...notice};
                this.editModalNoticeVisible = true;
            }
        },
        getNoticeById(id){
            // tableNoticeData是公告数据的数组
            return this.tableNoticeData.find(notice => notice.id === id);
        },
        addNotice() {
            this.$refs.newNoticeForm.validate((valid) => {
                if (valid) {
                    // 执行提交逻辑
                    axios.post("/pa/notice/addNotice",v.newNotice,{
                        headers: {
                            'token': localStorage.getItem('localJwt'),
                            // 'Content-Type': 'application/json'
                        }}).then(function (response) {
                        if(response.data.code===1){
                            v.$message.success("添加成功");
                            v.resetNewNotice();
                            v.dialogNoticeVisible = false;
                            v.showNoticeInfo();
                            v.showIndexNotice();
                        }
                    })
                }
            });
        },
        resetNoticeForm(){//重置公告信息
            v.newNotice = {
                notice: '',
                issueTime: '',
            };
        },
        /*===============================公告信息模块方法结束====================================*/
    },
    /*头像部分用得到*/
    mounted() {
        this.loadCurrentUserInfo();
    },

    mounted() {
        console.log("进来了")
        this.fetchData();
        this.renderIncomeChart();
        this.showIndexNotice();//公告信息模块
        this.getDepartments();//
        this.checkToken();

    },


})
